package com.example.android.google.apis;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.android.apis.view.Map;
import com.example.android.logging.Logger;
import com.example.android.network.Client;

public class MainActivity extends Activity {

	final int serverPort = 50001;
	final String defaultServerIp = "192.168.1.109";
	public static String login;
	private TextView textIp;
	private TextView textLogin;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Logger.CurrentContext = this;
		setContentView(R.layout.activity_main);

		final Button button = (Button) findViewById(R.id.go_button);
		textIp = (TextView) findViewById(R.id.ip_EditText);
		textLogin = (TextView) findViewById(R.id.login_editText);

		button.setOnClickListener(new OnButtonClick());
		textIp.setText(defaultServerIp);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	private class OnButtonClick implements View.OnClickListener {
		public void onClick(View v) {
			final String serverIpAddress = String.valueOf(textIp.getText());
			String login = String.valueOf(textLogin.getText());

			Client.getInstance().connect(serverIpAddress, serverPort);
			MainActivity.login = login;

			Intent intent = new Intent(MainActivity.this, Map.class);
			MainActivity.this.startActivity(intent);
		}
	}
}
